package com.mszlu.blog.controller;

import com.mszlu.blog.common.aop.LogAnnotation;
import com.mszlu.blog.service.ArticleService;
import com.mszlu.blog.vo.Result;
import com.mszlu.blog.vo.params.ArticleParam;
import com.mszlu.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.mszlu.blog.controller
 * @ClassName: ArticleController
 * @Author: 陈威
 * @CreateTime: 2021/8/27 14:52
 * @Description:
 */
@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    ArticleService articleService;
    //首页文章列表
    @PostMapping
    @LogAnnotation(module="文章",operation="获取文章列表") //加上此注解 代表 要对该接口记录日志
    public Result listArticle(@RequestBody PageParams params) {
        Result result = articleService.listArticle(params);
        return result;
    }

    //后台管理文章列表
    @PostMapping("/listArticleAll")
    @LogAnnotation(module="文章",operation="获取文章列表") //加上此注解 代表 要对该接口记录日志
    public Result listArticleAll(@RequestBody PageParams params) {
        Result result = articleService.listArticleAll(params);
        return result;
    }

    //最热文章列表
    @PostMapping("/hot")
    @LogAnnotation(module="文章",operation="最热文章列表") //加上此注解 代表 要对该接口记录日志
    public Result hotArticle() {
        int limit = 3;
        Result result = articleService.hotArticle(limit);
        return result;
    }

    //最新文章列表
    @PostMapping("/new")
    @LogAnnotation(module="文章",operation="最新文章列表") //加上此注解 代表 要对该接口记录日志
    public Result newArticle() {
        int limit = 3;
        return articleService.newArticle(limit);
    }

    //文章归档
    @PostMapping("/listArchives")
    @LogAnnotation(module="文章",operation="文章归档") //加上此注解 代表 要对该接口记录日志
    public Result listArchives() {
        return articleService.listArchives();
    }

    //查看文章详细信息
    @PostMapping("view/{id}")
    @LogAnnotation(module = "文章",operation = "文章详细信息")
    public Result findArticleById(@PathVariable("id")Long id){
        return articleService.findArticleById(id);
    }




    //发布文章或修改文章
    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        Result publish = articleService.publish(articleParam);
        return publish;
    }

    //删除文章
    @PostMapping("deleteArticle/{id}")
    public Result deleteArticle(@PathVariable("id")Long id){
        articleService.deleteArticle(id);
        return Result.success("hhh");
    }

}